<?php
 class User extends Connection{
    
    public $fname;
    public $username;
    public $password;
    public $mname;
    public $lname;
    public $email;
    
    function __construct(){
        parent::__construct();
    }


    public function enc($str = ""){
        
        return md5(sha1(trim($str)));
    }
    public function login(){
        $password = $this->enc($this->password);
        $sql = "select * from users where username='".trim($this->username)."' and password ='".$password."'";
        $result = $this->query($sql);
        
        if(count($result) > 0){
             //save session
            session_start();
            $_SESSION["username"] = $result["username"];
            
            return true;
            
            
        }
        else{
            return false;
        }
    }
    
    
    
    public function register(){
    $password = $this->enc($this->password);
    $sql = "insert into users(firstname,middlename,lastname,username,password,email) values ('".
     trim($this->fname)."','".trim($this->mname)."','".trim($this->lname)."','".trim($this->username)."','".
     $password."','".$this->email."')";
     
     //execute sql;
     $result = $this->transact($sql);
     return $result;
   }
 
 
 }